#include "main.h"

int main()
{
    Uint32 temps_courant, prochain_rendu = 0;
    int continuer = 1, frameLimit = 16;
    int i=0;
   
  

    init("Project ES-45");
    loadGame();
    initializePlayer();
    initializeMonster(&i);


    while(continuer)
    {
        getInput();
        
        if(jeu.onMenu == 0)
        {
           updatePlayer();
           doFireballs();

           updateMonsters();
           draw();

        delay(frameLimit);
        frameLimit = SDL_GetTicks() + 16; 
        temps_courant = SDL_GetTicks();
        
        if (temps_courant > prochain_rendu)
        {
            prochain_rendu = temps_courant +1000;

           initializeMonster(&i);}

        }
        else
        {
            if(jeu.menuType == START)
               { 
                updateStartMenu();}
            else if(jeu.menuType == PAUSE)
               { updatePauseMenu(input);

                 }}


if(jeu.onMenu == 0)
        {
           
            draw();
        }
        else
        {
            if(jeu.menuType == START)
            {
                drawImage(map.background, 0, 0);
                drawStartMenu();
                SDL_Flip(jeu.screen);
                SDL_Delay(1);
            }
            else if(jeu.menuType == PAUSE)
            {
                drawImage(map.background, 0, 0);
                drawMap();
                drawAnimatedEntity(&player);
                for(i = 0 ; i < jeu.nombreMonstres ; i++)
                {
                    drawAnimatedEntity(&monster[i]);
                }
                drawHud();
                drawFireballs();
                drawPauseMenu();
                SDL_Flip(jeu.screen);
                SDL_Delay(1);
            }
            }
                
    }

    cleanup();
    return 0;
}
